package org.game.module.event.listener;

import java.util.Map;

import org.constant.EventConditionKey;
import org.constant.EventConditionType;
import org.constant.EventType;
import org.game.db.bean.Player;
import org.game.plugin.event.GameEvent;
import org.game.plugin.event.GameEventListener;
import org.game.plugin.event.GameEventStack;
import org.game.plugin.event.GameEventType;

import com.sojoys.artifact.tools.ToolMap;

/**
 * @author : DengYing
 * @CreateDate : 2018年1月10日 上午10:12:56
 * @Description ：任务接取事件监听
 */
@GameEventType(EventType.TASK_ACCEPT)
public class TaskAcceptListener implements GameEventListener{

	@Override
	public void onEvent(GameEvent event) {
		Player player = event.getPlayer();
		GameEventStack eventStack = event.peek();
		switch (eventStack.getConditionType()) {
		case EventConditionType.TASK_ACCEPT: {
			boolean bool = true;

			// 等级检查
			int plvl = ToolMap.getInt(EventConditionKey.PLAYER_LVL, eventStack.getParams());
			if (plvl > 0) {
				bool &= player.getLevel() >= plvl;
			}
			
			
			// 前置任务检查
			int preTaskId = ToolMap.getInt(EventConditionKey.PRE_TASK_ID, eventStack.getParams());
			if (preTaskId>0) {
				Map<Integer,Integer> finishTasks =  player.getPlayerDatasFkPlayerId().getPlayerDataProxy().getFinishTasks();
				bool &= (finishTasks.containsKey(preTaskId));
			}
			
			
			
			if (bool) {
				eventStack.setProgress(1);
			}
		}
			break;
		default:
			break;
		}
	}

	@Override
	public void initEventCondition(Player player, GameEventStack eventStack) {
		
	}

}
